<?php
// TODO: переделать библиотеку, чтобы по умолчанию поддерживался imageMagic - http://articles.sitepoint.com/article/dynamic-images-imagemagick

$captcha_config['length']    = 5;
$captcha_config['imgheight'] = 24;
$captcha_config['fontsize']  = 16;
$captcha_config['font']      = 'PlAGuEdEaTH.ttf';

$captcha_config['angle']     = 2;
#$captcha_config['lines']     = false;
#$captcha_config['noize']     = true;

#$captcha_config['type']      = 'png'; # jpg
#$captcha_config['symbols']   = "ABCDEFGHIJKLNMPQRSTUVWXYZ123456789";
#$captcha_config['bgcolor']   = 'FFFFFF';
$captcha_config['textcolor'] = 'CCCCCC';
#$captcha_config['casesense'] = false;

/*
 * FONTS:
 * pirulen.ttf
 * karabine.ttf
 * Gemerald.ttf
 * GenBasR.ttf
 * moonflower.ttf
 * absci.ttf
 * abscib.ttf
 * ace.ttf
 * actionis.ttf
 * aescrawl.ttf
*/

require_once(ROOT . LIBRARY .'/captcha.class.inc');

$CP = new Captcha($captcha_config);

if(!empty($_GET))
{
   # CHECK CODE THROUGH AJAX

   $v = $_GET;
   while(is_array($v)) list($k, $v) = each($v);
   if(!empty($v))
   {
      $captcha_gues_count = session::getVar('captcha_gues_count');
      $captcha_gues_count = $captcha_gues_count ? $captcha_gues_count + 1 : 1;
      $respond            = FALSE;

      if($CP->verifyCaptcha($v) && $captcha_gues_count < 25)
      {
         $respond            = TRUE;
         $captcha_gues_count = 0;
      }
      session::setVar('captcha_gues_count', $captcha_gues_count);
      echo json_encode($respond);
      exit();
   }
}


$CP->createCaptcha();
exit();